using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerDashState : PlayerState
{
    public PlayerDashState(Player _player, PlayerStateMachine _stateMachine, string _animBoolName) : base(_player, _stateMachine, _animBoolName)
    {
    }

    public override void Enter()
    {
        base.Enter();
        player.skill.dash.CloneOnDash();//冲刺开始释放幻影 开关在克隆技能里
        stateTimer = player.dashDuration;// 冲刺时间
        player.stats.MakeInvincible(true);//设置玩家为无敌状态
    }

    public override void Exit()
    {
        base.Exit();
        player.skill.dash.CloneOnArrival();//冲刺结束释放幻影
        player.SetVelocity(0, rb.velocity.y);// 防止滑动
        player.stats.MakeInvincible(false);//取消玩家的无敌状态
    }

    public override void Update()
    {
        base.Update();

        if (!player.IsGroundDetected() && player.IsWallDetected())
        {
            stateMachine.ChangeState(player.wallSlide);// 冲刺状态不在地面且遇到墙体转为滑墙状态
        }

        player.SetVelocity(player.dashSpeed * player.dashDir, 0);// 冲刺

        if (stateTimer < 0)
        {
            stateMachine.ChangeState(player.idleState);// 冲刺完转为待机状态
        }

        player.fx.CreateAfterImage();//创建残影
    }
}

